package com.navid.trafalgar.mod.counterclock;

import com.jme3.app.Application;
import com.jme3.system.AppSettings;
import com.navid.trafalgar.model.GameConfiguration;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.controls.ListBox;
import de.lessvoid.nifty.controls.ListBoxSelectionChangedEvent;
import de.lessvoid.nifty.controls.RadioButtonGroupStateChangedEvent;
import de.lessvoid.nifty.controls.RadioButtonStateChangedEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 *
 * @author alberto
 */
public class PreCounterClockShip implements ScreenController {

    private Nifty nifty;
    private Screen screen;
    private CounterClockMain game;
    GameConfiguration gc;
    PreCounterClockShip.ListItem selectedItem;

    public PreCounterClockShip(CounterClockMain windMain) {
        game = windMain;
    }

    public void bind(Nifty nifty, Screen screen) {
        this.nifty = nifty;
        this.screen = screen;
    }

    private static class ListItem {

        private String name;
        private String picture;

        /**
         * @return the name
         */
        public String getName() {
            return name;
        }

        /**
         * @param name the name to set
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * @return the picture
         */
        public String getPicture() {
            return picture;
        }

        /**
         * @param picture the picture to set
         */
        public void setPicture(String picture) {
            this.picture = picture;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    public void onStartScreen() {
        fillListWithShips();
        gc = new GameConfiguration();
    }

    public void onEndScreen() {
        emptyList();
    }

    private void fillListWithShips() {
        ListBox shipList = screen.findNiftyControl("shipList", ListBox.class);

        com.navid.trafalgar.mod.counterclock.PreCounterClockShip.ListItem item1 = new com.navid.trafalgar.mod.counterclock.PreCounterClockShip.ListItem();
        item1.setName("ModelZero");
        shipList.addItem(item1);

        com.navid.trafalgar.mod.counterclock.PreCounterClockShip.ListItem item2 = new com.navid.trafalgar.mod.counterclock.PreCounterClockShip.ListItem();
        item2.setName("ModelOne");
        shipList.addItem(item2);

        selectedItem = item1;
    }

    private void emptyList() {
        ListBox shipList = screen.findNiftyControl("shipList", ListBox.class);

        shipList.clear();
    }

    @NiftyEventSubscriber(id = "shipList")
    public void onShipChanged(final String id, final ListBoxSelectionChangedEvent<com.navid.trafalgar.mod.counterclock.PreCounterClockShip.ListItem> event) {
        selectedItem = event.getSelection().get(0);
    }

    

    public void goTo(String nextScreen) {
        gc.setShipName(selectedItem.getName());
        game.setGameShipConfiguration(gc);

        nifty.gotoScreen(nextScreen);  // switch to another screen
    }
}
